﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Finder.Utilities.KeyCapture
{
    /// <summary>
    /// Represet a hot key. A pair of keys ie. ALT + K.
    /// </summary>
    public class HotKey
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HotKey"/> class. 
        /// Sets the hot key.
        /// </summary>
        /// <param name="key1">
        /// The key1 part.
        /// </param>
        /// <param name="key2">
        /// The key2 part.
        /// </param>
        public HotKey(HotKeyPart key1, HotKeyPart key2)
        {
            this.Key1 = key1;
            this.Key2 = key2;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HotKey"/> class. 
        /// Sets the hot key.
        /// </summary>
        /// <param name="key1">
        /// The key1 part.
        /// </param>
        /// <param name="key2">
        /// The key2 part.
        /// </param>
        public HotKey(int key1, int key2)
        {
            this.Key1 = new HotKeyPart(key1, string.Empty);
            this.Key2 = new HotKeyPart(key2, string.Empty);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HotKey"/> class.
        /// </summary>
        public HotKey()
        {
        }

        /// <summary>
        /// Gets or sets Key1.
        /// </summary>
        public HotKeyPart Key1 { get; set; }

        /// <summary>
        /// Gets or sets Key2.
        /// </summary>
        public HotKeyPart Key2 { get; set; }

        /// <summary>
        /// Gets a value indicating whether this instance is set.
        /// </summary>
        /// <value><c>true</c> if this instance is set; otherwise, <c>false</c>.</value>
        public bool IsSet
        {
            get { return this.Key1 != null && this.Key2 != null; }
        }

        /// <summary>
        /// Clears the hot key.
        /// </summary>
        public void Clear()
        {
            this.Key1 = this.Key2 = null;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return this.Key1 + " + " + this.Key2;
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is HotKey)
            {
                HotKey hk = (HotKey)obj;

                return (this.Key1.KeyCode == hk.Key1.KeyCode) && (this.Key2.KeyCode == hk.Key2.KeyCode);
            }

            return false;
        }
    }
}
